package com.itxx.Keycase;

import com.itxx.Keycase.domain.Studnet;

import java.text.Collator;
import java.util.*;

//今日案例[Stream]:TreeMap的排序使用 1 / toMap(不重要) 练一下. / 男女演员题目练习 3 / Day14作业的Stream流部分[最后一题不做]
public class TreeMapDemo {
    public static void main(String[] args) {
        TreeMap<Studnet, String> treeMap = new TreeMap<>(new Comparator<Studnet>() {
            @Override
            public int compare(Studnet studnet, Studnet t1) {
                int result = studnet.getAge() - t1.getAge();
                if (result == 0) {
                    Collator instance = Collator.getInstance(Locale.CHINA);
                    instance.compare(studnet.getName(), t1.getName());
                }
                return result;
            }
        });
        treeMap.put(new Studnet("张三", 23), "上海");
        treeMap.put(new Studnet("李四", 24), "北京");
        treeMap.put(new Studnet("阿斯", 16), "天宁");
        treeMap.put(new Studnet("缪斯", 61), "天津");
        treeMap.put(new Studnet("丘比特", 77), "西安");
        Set<Map.Entry<Studnet, String>> entries = treeMap.entrySet();
        for (Map.Entry<Studnet, String> entry : entries) {
            Studnet key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key + "...." + value);
        }

    }
}
